home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Why is Gets() so bad?
- Date: 03 Mar 1996 22:30:40 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar3153040@qcd.lanl.gov>
- References: <4hb1ie$pa7@ixnews2.ix.netcom.com> <4hcvef$308@qns2.qns.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: mjarvis@qns2.qns.com's message of 3 Mar 1996 14:29:03 -0600
-
- In article <4hcvef$308@qns2.qns.com>
- mjarvis@qns2.qns.com (Michael Jarvis) writes:
-
- <snip>
- MJ: if ( fgets( buf, sizeof(buf)-1, stdin ) == NULL )
-
- The fgets function reads at most one less than the number of
- characters specified by its second argument. It appends a '\0' (unless
- an eof took place before it read anything): so the total number of
- characters written cannot exceed the number specified.
-
- MJ: perror( "Error reading in gets()");
- MJ:
- MJ: printf( "The buf=\"%s\"\n", buf );
-
- You should be careful about fgets: it retains the newline character
- (provided it has space of course). Note that if fgets fails, you
- should not use buf without checking further: the contents could be
- indeterminate.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-